package com.ysg.widget.table;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ysg.R;
import com.ysg.utils.YDisplayUtil;
import com.ysg.utils.YStringUtil;

/**
 * 表格单元格
 */
public class YTableCell extends RelativeLayout {
    private TextView tvName;

    public YTableCell(Context context) {
        super(context);
    }

    public YTableCell(Context context, AttributeSet attrs) {
        super(context, attrs);

        View view = View.inflate(context, R.layout.widget_table_cell, this);
        tvName = view.findViewById(R.id.tvName);

        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.YTableCell);
        boolean enable = array.getBoolean(R.styleable.YTableCell_enable, false);
        String content = array.getString(R.styleable.YTableCell_content);
        int width = array.getDimensionPixelOffset(R.styleable.YTableCell_width, YDisplayUtil.dip2px(context, 70));
        array.recycle();

        //内容
        if (YStringUtil.isNotEmpty(content)){
            tvName.setText(content);
        }

        //宽度
        ViewGroup.LayoutParams layoutParams = tvName.getLayoutParams();
        layoutParams.width = width;
        view.setLayoutParams(layoutParams);

        //可编辑颜色
        if (enable){
            tvName.setTextColor(getResources().getColor(R.color.themeColor));
        }
    }

    public void setContent(String content){
        tvName.setText(content);
    }





}
